from rest_framework.viewsets import GenericViewSet
from utils.viewsets import ReadOnlyModelViewSet
from utils.mixins import *


from apps.HttpTestcase.models import  Interfaces
from apps.HttpTestcase.filters import InterfacesFilter
from apps.HttpTestcase.serializers import InterfacesModeSerializer, CreateMOdelSerializer


class APIListViewSet(ReadOnlyModelViewSet):
    """
    Api列表及ID查询
    """
    perms_map = {'get': '*', 'post': 'api_create',
                 'put': 'api_update', 'delete': 'api_delete'}
    queryset = Interfaces.objects.filter(is_delete=False)
    filter_class = InterfacesFilter
    serializer_class = InterfacesModeSerializer

    # 指定权限类
    # permission_classes = [permissions.IsAuthenticated]


class ApiViewSet(DestroyModelMixin, CreateModelMixin, UpdateModelMixin, GenericViewSet):
    queryset = Interfaces.objects.filter(is_delete=False)
    serializer_class = CreateMOdelSerializer

    def perform_destroy(self, instance):
        instance.is_delete = True
        instance.save()  # 逻辑删除
